using System;
using System.Collections.Generic;

namespace MongoScienceDAL.Core.Tests
{
    public abstract class MongoRepositoryTestBase
    {
        public string CollectionName = "testCollection";

        public IScienceRepository GetRepositoryForExistingCollectionWithTypes()
        {
            //clear database
            TestHarness.ResetDatabase();

            //We need to setup a collection
            var dataSource = TestHarness.DataSource;

            var scienceCollection = new ScienceCollection
            {
                Index = 1,
                CreatedBy = "testuser",
                CreatedOn = new DateTime(1985, 5, 23),
                Description = "test collection",
                Name = CollectionName
            };

            scienceCollection = dataSource.AddCollection(scienceCollection);

            //Add some types
            var testType1 = new ScienceType
            {
                CreatedBy = "testuser",
                CreatedOn = new DateTime(1985, 5, 23),
                Description = "test description",
                Hidden = false,
                Index = 1,
                Key = "t1",
                Name = "test1",
                Required = false,
                Settings = new Dictionary<string, string>(),
                Type = ScienceTypeEnum.Text
            };

            var testType2 = new ScienceType
            {
                CreatedBy = "testuser",
                CreatedOn = new DateTime(1985, 5, 23),
                Description = "test description",
                Hidden = false,
                Index = 1,
                Key = "t2",
                Name = "test2",
                Required = false,
                Settings = new Dictionary<string, string>(),
                Type = ScienceTypeEnum.Text
            };

            var testType3 = new ScienceType
            {
                CreatedBy = "testuser",
                CreatedOn = new DateTime(1985, 5, 23),
                Description = "test description",
                Hidden = false,
                Index = 1,
                Key = "t3",
                Name = "test3",
                Required = false,
                Settings = new Dictionary<string, string>(),
                Type = ScienceTypeEnum.Text
            };

            dataSource.AddCollectionType(scienceCollection.Name, testType1);
            dataSource.AddCollectionType(scienceCollection.Name, testType2);
            dataSource.AddCollectionType(scienceCollection.Name, testType3);

            //return a repo
            return new ScienceRepository(dataSource, CollectionName);
        }
    }
}